package com.openlab.callsystem.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.openlab.callsystem.entity.Log;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author cyq
 * @since 2021-11-14
 */
@Mapper
public interface LogMapper extends BaseMapper<Log> {

    public void insert(Integer callerId, String callerName, Integer windowsId,
                       Integer businessType, Integer isSuccess, LocalDateTime date, Integer num);
    @Delete("RUNCATE TABLE log")
    public long delete();
    @Delete("delete id from log where date=#{date}")
    public long deleteByDate(@Param("date") java.sql.Date date);
    @Select("select * from log")
    public List<Log> queryAll();
    @MapKey("date")
    @Select("SELECT date,count(*) FROM log group by date")
    public Map<String,Integer> queryAllByDay();//每日业务量
    @Select("SELECT COUNT(*) from log where businessType=#{business} and date=(SELECT MAX(date) from log) ;")
    public Integer queryTodayLogNumber(Integer business);
    @MapKey("date")
    @Select("SELECT date,count(*) FROM log where businessType=#{businessType} group by date")
    public Map<String,Integer> queryByDay(int businessId);
    @Select("SELECT callerName,count(*) from log   WHERE businessType=#{businessType} GROUP BY callerName")
    public Map<String,Integer> queryWorkload(int businessId);
    @Select("select max(num) from log where businessType =#{businessType};")
    public Integer calNumber(Integer businessType);
    @Select("select count(*) from log where businessType=1 ")
    public Integer calVip();
    @Select("select count(*) from log where businessType=2 ")
    public Integer calCommon();
    @Select("select count(*) from log where isSuccess=1 ")
    public Integer calSuccess();
    @Select("select count(*) from log where isFaild=1 ")
    public Integer calFaild();
}
